import { GetOrganizationList } from "@/service/index.js";
import $store from "@/store/index.js";
import { ref } from "vue";
import enums from "@/enums";

export const chooseOrgConfig = ref({
  multipleSelect: true, //[默认false,即单选框]多选还是单选,
  returnShowColomn: "name", //[*]组件回显的字段,显示在input框里的数据
  tooltip: ["fathername", "name"], //[]气泡回显的字段,可以配置一个也可以配置多个字段,如果配置多个,回显时使用##连接
  searchConfig: {
    //搜索区域配置
    labelWidth: "100px",
    itemStyle: {
      padding: "10px"
    },
    colLayout: {
      span: 7
    },
    formItems: [
      {
        field: "district",
        type: "select",
        label: "所属区县",
        placeholder: "请选择区县",
        //vIf:($store.state.userInfo.authenticationType=='3'||$store.state.userInfo.authenticationType=='4') && $store.state.userInfo.districtCode==enums.MAX_DISTRICT_LEVEL_CODE,
        options: $store.getters.getOptionsFromDicBySetName(enums.SETNAME_DISTRICT),
        otherOptions: {
          filterable: true
        }
      },
      {
        field: "name",
        type: "input",
        label: "单位名称",
        placeholder: "请输入单位名称"
      }
    ]
  },
  detailPropList: [
    //[*]表格的列信息
    { prop: "name", label: "组织机构", minWidth: "150" },
    { prop: "fathername", label: "上级组织名称", minWidth: "150" },
    {
      prop: "type",
      label: "类型",
      minWidth: "80",
      codeMap: [
        //表格里如果有code,转化
        { title: "化工企业", value: "1" },
        { title: "承包商", value: "2" },
        { title: "政府", value: "3" },
        { title: "企业部门", value: "11" },
        { title: "政府部门", value: "31" },
        { title: "市区", value: "市区" },
        { title: "区县", value: "区县" },
        { title: "园区", value: "园区" }
      ]
    },
    { prop: "districtcode", label: "区县代码", minWidth: "100" },
    { prop: "districtname", label: "所属区县", minWidth: "100" }
  ],
  selectedPropList: [
    //[只有多选功能时生效]已选中区域的表格的信息
    { prop: "name", label: "组织机构", minWidth: "120" },
    { prop: "fathername", label: "上级组织名称", minWidth: "120" }
  ],
  getDataFunction: (pagenum, pagesize, queryInfo) => {
    //[*]数据查询方法,每次改动条件重新查询或者改动页码都会重新执行该方法,并渲染
    let params = { ...queryInfo, pageIndex: pagenum, pageSize: pagesize };
    return new Promise(resolve => {
      GetOrganizationList(params).then(res => {
        if (res.data && res.code == "200") {
          const querysuccess = true;
          const totalcount = res.total;
          const datalist = res.data;
          resolve({ querysuccess, totalcount, datalist });
        } else {
          const querysuccess = false;
          const totalcount = 0;
          const datalist = [];
          resolve({ querysuccess, totalcount, datalist });
        }
      });
    });
  }
});
